#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2018/12/11 14:12
# @Author  : yangdy
# @Email   : yangdy@egu360.com
# @File    : 高级-四数相加II.py
# @Software: PyCharm


class Solution:
    def fourSumCount(self, A, B, C, D):
        """
        :type A: List[int]
        :type B: List[int]
        :type C: List[int]
        :type D: List[int]
        :rtype: int
        """
        m = {}
        la = len(A)
        lb = len(B)
        lc = len(C)
        ld = len(D)
        for i in range(la):
            for j in range(lb):
                x = A[i] + B[j]
                if not m.get(x):
                    m[x] = 1
                else:
                    m[x] += 1
        ans = 0
        for i in range(lc):
            for j in range(ld):
                x = - C[i] - D[j]
                if m.get(x):
                    ans += m[x]
        return ans
